undefined reference to `main' collect2: ld returned 1 exit status

Posted by sobingt on Stack Overflow See other posts from Stack Overflow or by sobingt
Published on 2012-05-10T09:56:28Z Indexed on 2012/06/12 4:40 UTC
Read the original article Hit count: 898

Filed under:
|
|

I am working on this QT project and i am making test cases for my project. Here is a small test case

#include <QApplication>
#include <QPalette>
#include <QPixmap>
#include <QSplashScreen>
#include <qthread.h>

#define BOOST_TEST_MAIN
#include <boost/test/unit_test.hpp>
#include <boost/make_shared.hpp>
#    include <boost/thread.hpp>

#include "MainWindow.h"

namespace
{
    const std::string dbname = "Project.db";

    struct SongFixture
    {
        SongFixture(const std::string &fixturePath)
        {
            // Create the Master file
            Master::creator();

            // Create/open file
            std::pair<int, SQLiteDbPtr> result = open(
                    dbname, SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE, 0);
            if (result.first != SQLITE_OK)
            {
                throw SQLiteError(result.first,
                        sqlite3_errmsg(result.second.get()));
            }
            SQLiteDbPtr &spDb = result.second;

            // Execute all the SQL from the fixture file
            execSQLFromFile(spDb, fixturePath);
        }
    };

    std::auto_ptr<SongFixture> pf;
}

class I : public QThread
{
public:
    static void sleep(unsigned long secs) {
        QThread::sleep(secs);
    }
};

void free_test_function()
{
   BOOST_CHECK(true );
}

test_suite*
init_unit_test_suite(int argc, char *argv[])
{
    // Create a fixture for the peer:
    // Manage fixture creation manually instead of using
    // BOOST_FIXTURE_TEST_CASE because the fixture depends on runtime args.
    std::ostringstream fixturePathSS;
    fixturePathSS << PROJECT_DIR << "/test/songs_fixture.sql";
    std::string fixturePath = fixturePathSS.str();

    pf.reset(new SongFixture(fixturePath));
    QApplication app(argc, argv);
    MainWindow window("artists");
    window.show();

    framework::master_test_suite().add( BOOST_TEST_CASE( &free_test_function ));
    return app.exec();
}

Well i am getting any error

/usr/lib/gcc/x86_64-linux-gnu/4.6.1/../../../x86_64-linux-gnu/crt1.o: In function _start': (.text+0x20): undefined reference tomain' collect2: ld returned 1 exit status

pls help me you have a lead..thankz


I tired adding

#define BOOST_TEST_MAIN then i get

../test/UI/main.cpp: In function ‘boost::unit_test::test_suite* init_unit_test_suite(int, char**)’:
../test/UI/main.cpp:75:31: error: redefinition of ‘boost::unit_test::test_suite* init_unit_test_suite(int, char**)’
/usr/local/include/boost/test/unit_test_suite.hpp:223:1: error: ‘boost::unit_test::test_suite* init_unit_test_suite(int, char**)’ previously defined here

Well the program is working in Windows but in Linux the above mention problem is observed

© Stack Overflow or respective owner

Related posts about unit-testing

Related posts about qt